home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / fax / src / libtiff / tif_fax4.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  3KB  |  115 lines

  1. #ifndef lint
  2. static char rcsid[] = "$Header: /usr/people/sam/fax/libtiff/RCS/tif_fax4.c,v 1.21 1993/03/30 18:26:37 sam Exp $";
  3. #endif
  4.  
  5. /*
  6.  * Copyright (c) 1990, 1991, 1992 Sam Leffler
  7.  * Copyright (c) 1991, 1992 Silicon Graphics, Inc.
  8.  *
  9.  * Permission to use, copy, modify, distribute, and sell this software and 
  10.  * its documentation for any purpose is hereby granted without fee, provided
  11.  * that (i) the above copyright notices and this permission notice appear in
  12.  * all copies of the software and related documentation, and (ii) the names of
  13.  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  14.  * publicity relating to the software without the specific, prior written
  15.  * permission of Sam Leffler and Silicon Graphics.
  16.  * 
  17.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  18.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  19.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  20.  * 
  21.  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  22.  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  23.  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  24.  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
  25.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  26.  * OF THIS SOFTWARE.
  27.  */
  28.  
  29. /*
  30.  * TIFF Library.
  31.  *
  32.  * CCITT Group 4 Facsimile-compatible
  33.  * Compression Scheme Support.
  34.  */
  35. #include "tiffiop.h"
  36. #include "tif_fax3.h"
  37. #include "t4.h"
  38.  
  39. /*
  40.  * Decode the requested amount of data.
  41.  */
  42. static int
  43. DECLARE4(Fax4Decode, TIFF*, tif, u_char*, buf, u_long, occ, u_int, s)
  44. {
  45.     Fax3BaseState *sp = (Fax3BaseState *)tif->tif_data;
  46.     int status;
  47.  
  48.     memset(buf, 0, occ);        /* decoding only sets non-zero bits */
  49.     while ((long)occ > 0) {
  50.         status = Fax3Decode2DRow(tif, buf, sp->rowpixels);
  51.         if (status < 0)
  52.             return (status == G3CODE_EOF);
  53.         memcpy(sp->refline, buf, sp->rowbytes);
  54.         buf += sp->rowbytes;
  55.         occ -= sp->rowbytes;
  56.         if (occ > 0)
  57.             tif->tif_row++;
  58.     }
  59.     return (1);
  60. }
  61.  
  62. /*
  63.  * Encode the requested amount of data.
  64.  */
  65. static int
  66. DECLARE4(Fax4Encode, TIFF*, tif, u_char*, bp, u_long, cc, u_int, s)
  67. {
  68.     Fax3BaseState *sp = (Fax3BaseState *)tif->tif_data;
  69.  
  70.     while ((long)cc > 0) {
  71.         if (!Fax3Encode2DRow(tif, bp, sp->refline, sp->rowpixels))
  72.             return (0);
  73.         memcpy(sp->refline, bp, sp->rowbytes);
  74.         bp += sp->rowbytes;
  75.         cc -= sp->rowbytes;
  76.         if (cc > 0)
  77.             tif->tif_row++;
  78.     }
  79.     return (1);
  80. }
  81.  
  82. static
  83. DECLARE1(Fax4PostEncode, TIFF*, tif)
  84. {
  85.     Fax3BaseState *sp = (Fax3BaseState *)tif->tif_data;
  86.  
  87.     /* terminate strip w/ EOFB */
  88.     Fax3PutBits(tif, EOL, 12);
  89.     Fax3PutBits(tif, EOL, 12);
  90.     if (sp->bit != 8)
  91.         Fax3FlushBits(tif, sp);
  92.     return (1);
  93. }
  94.  
  95. int
  96. DECLARE1(TIFFInitCCITTFax4, TIFF*, tif)
  97. {
  98.     TIFFInitCCITTFax3(tif);        /* reuse G3 compression */
  99.     tif->tif_decoderow = Fax4Decode;
  100.     tif->tif_decodestrip = Fax4Decode;
  101.     tif->tif_decodetile = Fax4Decode;
  102.     tif->tif_encoderow = Fax4Encode;
  103.     tif->tif_encodestrip = Fax4Encode;
  104.     tif->tif_encodetile = Fax4Encode;
  105.     tif->tif_postencode = Fax4PostEncode;
  106.     /*
  107.      * FAX3_NOEOL causes the regular G3 decompression
  108.      * code to not skip to the EOL mark at the end of
  109.      * a row (during normal decoding).  FAX3_CLASSF
  110.      * suppresses RTC generation at the end of an image.
  111.      */
  112.     tif->tif_options = FAX3_NOEOL|FAX3_CLASSF;
  113.     return (1);
  114. }
  115.